package pl.ptemich.tankwars.states;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import pl.ptemich.tankwars.TWLGame;
import pl.ptemich.tankwars.objects.Board;
import pl.ptemich.tankwars.tools.ScreenTools;
import pl.ptemich.tankwars.tools.StateTools;

public class BattleshipsState extends RegisteredState {

  private Board board;

  private int x = 10;
  private int y = 10;
  private int step = 1000;
  
  @Override
  public void init(GameContainer container, StateBasedGame game)
      throws SlickException {
    board = new Board(100, 100);       
  }
  
  @Override
  public void render(GameContainer container, StateBasedGame game, Graphics graphics)
      throws SlickException {
    board.render(graphics);
    
    ScreenTools tools = ((TWLGame) game).getScreenTools();
    graphics.drawString(x + ":" + y, tools.getScreenPosX(x), tools.getScreenPosY(y));
  }
  
  @Override
  public void update(GameContainer container, StateBasedGame game, int delta)
      throws SlickException {
    
    step -= delta;
    
    if (step < 0) {
      step = 1000;
      x++;
      y*=1.2;
    }
    
    Input input = container.getInput();
    if (input.isKeyDown(Input.KEY_ESCAPE)) {
      StateTools.stateTransition(MenuState.class);
    }
  }
}
